package com.cskaoyan.user.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.user.constants.UserRetCode;
import com.cskaoyan.user.dal.entitys.UserVerify;
import com.cskaoyan.user.form.UserRegisterRequest;
import com.cskaoyan.user.form.UserVerifyRequest;
import com.cskaoyan.user.service.IUserRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Aaliyah
 * @date 2022/9/21 10:46
 * @description: TODO
 */
@RestController
@RequestMapping("/user")
public class UserRegisterController {

    @Autowired
    IUserRegisterService userRegisterService;

    @PostMapping("/register")
    public ResponseData postUserRegister(@RequestBody UserRegisterRequest userRegisterRequest, HttpServletRequest request) throws Exception {
        UserRetCode userRetCode = userRegisterService.register(userRegisterRequest,request);
        if (UserRetCode.SUCCESS.getCode().equals(userRetCode.getCode())){
            return new ResponseUtil<>().setData(null);
        }
        return new ResponseUtil<>().setErrorMsg(userRetCode.getMessage());
    }

    @RequestMapping("/verify")
    public ResponseData verify(String uid ,String username, HttpServletRequest request) {
        // String username = map.get("username");
        // String uid = map.get("uid");
        UserVerifyRequest userVerifyRequest = new UserVerifyRequest();
        userVerifyRequest.setUuid(uid);
        userVerifyRequest.setUsername(username);
        userRegisterService.verify(userVerifyRequest);
        return new ResponseUtil<>().setData(null,"success");
    }
}
